'use strict'

const fs =require('fs');
const {Sequelize,DataTypes,Op} =require('sequelize');


const sql=new Sequelize('blog','postgres','200916',{
    host:'wwwwei.top',
    dialect:'postgres'
})
let files =fs.readdirSync(__dirname);

let resFiles =files.filter(item => {
    return item.endsWith('.js') && item !='index.js';
})

let resObj={}
resFiles.forEach(item =>{
    let modelName =item.replace('.js','');
    console.log(modelName);
    let tmpObj=require(__dirname+'/'+item);

    let tableName=modelName.toLowerCase();
    resObj[modelName] =sql.define(tableName,tmpObj);
    
})


resObj.Op=Op

resObj.sync=async() =>{
    sql.sync({force:true}).then(() =>{
        resObj.blog.bulkCreate([
            {
                biaoti:'大数据',
                zaiyao: '大数据仪表',
                neirong: '大数据盘',
                fenlei:'大数据',

                writer:'余华',
                datatime:'2022-04-06 08:47'




            },
            
        ])

    })

}


module.exports=resObj;